﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class EditMember : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        for (int i = 1; i <= 31; i++)
        {
            NgayS.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
        for (int i = 1; i <= 12; i++)
        {
            ThangS.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
        for (int i = 1970; i <= 2008; i++)
        {
            NamS.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
      //  string Username = Request["user"];
        ShoppingDataContext db = new ShoppingDataContext();

       
        var prodetails = from p in db.MEMBERs
                         where p.username == Session["user"]
                         select p;

        if (prodetails.Count() <= 0) return;
        DateTime datetime = prodetails.First().birthday;
        this.NgayS.SelectedValue = datetime.Day.ToString();
        this.ThangS.SelectedValue = datetime.Month.ToString();
        this.NamS.SelectedValue = datetime.Year.ToString();

        this.Name1.Text = prodetails.First().Fullname;
        this.Address.Text = prodetails.First().address;
        this.Phone.Text = prodetails.First().phone;

    }
    protected void Save_Click(object sender, EventArgs e)
    {
        ShoppingDataContext db = new ShoppingDataContext();
        ACCOUNT account = db.ACCOUNTs.Single(p => p.username == Session["user"]);
        MEMBER member = db.MEMBERs.Single(p => p.username == Session["user"]);
        if (account.password != this.Mat_Khau0.Text)
        {
            this.warnning.Text = "Sai Mật Khẩu!!!";
           this.warnning.Visible = true;
            return;
        }
        else
        {
            this.warnning.Visible = false;
            account.password = this.Mat_Khau.Text;


           
            member.Fullname = this.Name1.Text;
            member.birthday = new DateTime(int.Parse(this.NamS.Text), int.Parse(this.ThangS.Text),
                                         int.Parse(this.NgayS.Text));
            member.phone = this.Phone.Text;
            member.address = this.Address.Text;
            db.SubmitChanges();
        }
    }
}
